<?php
namespace app\common\model;
use think\Model;
use think\Validate;
use app\common\controller\Tools;
class BankAccount extends Model
{
	protected $table= 'bank_account';
	protected $pk = 'bank_account_id';

	// 验证规则
	protected $rule = [
		['bank_account_openning_bank|开户行', ['require']],
		['bank_account_number|银行账户', ['require']],
		['bank_account_name|账户对应公司名称', ['require']],
	]; 
	
	// 验证场景
	protected $scene = [
        'insert' => ['bank_account_openning_bank', 'bank_account_number', 'bank_account_name'],
    ];

    // 验证器
	public function intValidate()
	{
        $validate = new \think\Validate($this->rule);
        foreach ($this->scene as $k1=>$v1)
            $validate->scene($k1, $v1);
        return $validate;
    }


    protected static function init()
	{
		BankAccount::beforeInsert(function ($bankAccount) 
		{
			$merchant_id = session('merchant.merchant_id');
			$bankAccount['bank_account_merchant_id'] = $merchant_id;
		});
	}
}